package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.ProductDao;
import com.cn.wanxi.dao.impl.ProductImpl;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.ProductService;

import java.util.List;


public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductImpl();

    @Override
    public ResultModel findAll(ProductModel productModel) {

//        ResultModel resultModel = new ResultModel();
//        ProductDao productDao = new ProductImpl();
//        List<ProductModel> list = productDao.findAll(productModel);
//        resultModel.setData(list);
//        resultModel.setCode(0);
//        int count = productDao.getCount(productModel);
//        resultModel.setCount(count);
//        return new ResultModel("", 0, list, count);
        return ResultModel.getModel(productDao.findAll(productModel), productDao.getCount(productModel));
    }

    @Override
    public ResultModel updateEnable(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel updateField(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel delete(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel add(ProductModel model) {
//        ProductDao productDao = new ProductImpl();
//        int count = productDao.add(model);
        return ResultModel.getModel(productDao.add(model));
    }

    @Override
    public ResultModel findById(ProductModel model) {

        return ResultModel.getModel(productDao.findById(model));
    }

    @Override
    public ResultModel update(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel getCount(ProductModel productModel) {

        return  ResultModel.getModel(productDao.getCount(productModel));
    }

    @Override
    public List<ProductModel> getProductModelList(ProductModel productModel) {

        return productDao.getProductModelList(productModel);
    }

    @Override
    public ResultModel getFrontCount(ProductModel productModel) {
        return ResultModel.getModel(productDao.getFrontCount(productModel));
    }

    @Override
    public ResultModel findFrontById(ProductModel model) {
        return ResultModel.getModel(productDao.findFrontById(model));
    }
}
